<template>
	<view class="content">
		<view class="notice" v-if="text">
			<image src="@/static/img/err.png" mode="widthFix"></image>
			<uni-notice-bar scrollable background-color="#FFF3EE" :speed="speed" color="#BC7A25" :text="text" />
		</view>
		<view class="info">
			<view class="title">工薪阶层</view>
			<view class="img_bg">
				<image v-if="!img_1" src="@/static/img/work_1.png" mode="widthFix" @click="changeImg(1)"
					style="width: 80rpx;"></image>
				<image v-else :src="img_1" mode="aspectFit" @click="changeImg(1)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传劳动合同</view>
			</view>
			<view class="img_bg">
				<image v-if="!img_2" src="@/static/img/work_2.png" mode="widthFix" @click="changeImg(2)"
					style="width: 104rpx;"></image>
				<image v-else :src="img_2" mode="aspectFit" @click="changeImg(2)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传在职证明</view>
			</view>
		</view>
		<view class="info">
			<view class="title">私营企业主</view>
			<view class="img_bg">
				<image v-if="!img_3" src="@/static/img/work_3.png" mode="widthFix" @click="changeImg(3)"
					style="width: 106rpx;"></image>
				<image v-else :src="img_3" mode="aspectFit" @click="changeImg(3)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传营业执照</view>
			</view>
			<view class="img_bg">
				<image v-if="!img_4" src="@/static/img/work_4.png" mode="widthFix" @click="changeImg(4)"
					style="width: 86rpx;"></image>
				<image v-else :src="img_4" mode="aspectFit" @click="changeImg(4)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传税务登记证</view>
			</view>
			<view class="img_bg">
				<image v-if="!img_5" src="@/static/img/work_5.png" mode="widthFix" @click="changeImg(5)"
					style="width: 96rpx;"></image>
				<image v-else :src="img_5" mode="aspectFit" @click="changeImg(5)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传店面照片</view>
			</view>
		</view>
		<view class="info">
			<view class="title">网商</view>
			<view class="img_bg">
				<image v-if="!img_6" src="@/static/img/work_6.png" mode="widthFix" @click="changeImg(6)"
					style="width: 96rpx;"></image>
				<image v-else :src="img_6" mode="aspectFit" @click="changeImg(6)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传网站主页截图</view>
			</view>
			<view class="img_bg">
				<image v-if="!img_7" src="@/static/img/work_7.png" mode="widthFix" @click="changeImg(7)"
					style="width: 90rpx;"></image>
				<image v-else :src="img_7" mode="aspectFit" @click="changeImg(7)" class="img_demo"></image>
				<view class="hint"><text>*</text>上传支付宝交易记录</view>
			</view>
			<view class="img_bg">
				<image v-if="!img_8" src="@/static/img/work_8.png" mode="widthFix" @click="changeImg(8)"
					style="width: 106rpx;"></image>
				<image v-else :src="img_8" mode="aspectFit" @click="changeImg(8)" class="img_demo"></image>
				<view class="hint">上传营业执照</view>
			</view>
		</view>
		<!-- <view class="info">
			<view class="title">认证说明：</view>
			<view class="text">1.个人信用报告需<text>15日</text>内开具。</view>
			<view class="text">2.上传您的个人信用报告原件的照片。</view>
			<view class="text">3.请确认您上传的资料是清晰的。</view>
			<view class="text">4.审核时间：<text>3个工作日内</text></view>
			<view class="text">5.认证有效期：<text>6个月</text></view>
		</view> -->
		<view v-if="info.is_upload==1&&(info.passed==0||info.passed==1)" class="default_btn btn color_9" @click="hint">
			提交审核</view>
		<view v-else class="default_btn btn" @click="edit">提交审核</view>
	</view>
</template>

<script>
	import {
		fileUp,
		queryCertificate,
		editCertificate
	} from '@/common/js/index.js'
	export default {
		data() {
			return {
				userId: '',
				img_1: '',
				img_2: '',
				img_3: '',
				img_4: '',
				img_5: '',
				img_6: '',
				img_7: '',
				img_8: '',
				text: '',
				speed: 50,
				info: '',
			}
		},
		onLoad(e) {
			this.info = JSON.parse(e.info)
			this.userId = e.id
			this.query()
		},
		methods: {
			hint() {
				var text
				if (this.info.passed == 0) text = '审核中…'
				if (this.info.passed == 1) text = '已上传'
				uni.showToast({
					title: text,
					icon: 'none',
					duration: 2000
				})
			},
			query() {
				queryCertificate({
					type_id: 2,
					user_id: this.userId
				}).then(res => {
					console.log(res);
					this.img_1 = res.data.images[0]
					this.img_2 = res.data.images[1]
					this.img_3 = res.data.images[2]
					this.img_4 = res.data.images[3]
					this.img_5 = res.data.images[4]
					this.img_6 = res.data.images[5]
					this.img_7 = res.data.images[6]
					this.img_8 = res.data.images[7]
					this.text = res.data.msg
				})
			},
			edit() {
				var img = [this.img_1 || '', this.img_2 || '', this.img_3 || '', this.img_4 || '', this.img_5 || '', this
					.img_6 || '', this.img_7 || '', this.img_8 || ''
				]
				editCertificate({
					type_id: 2,
					user_id: this.userId,
					images: JSON.stringify(img)
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					}
					console.log(res);
				})
			},
			changeImg(num) {
				if (this.info.is_upload == 1 && (this.info.passed == 0 || this.info.passed == 1)) {
					this.hint()
					return
				}
				console.log(this.userId);
				var that = this
				uni.chooseImage({
					count: 1,
					sizeType: ["compressed"],
					success(response) {
						console.log(response);
						// 选择图片后, 返回的数据
						var fileUrl = response.tempFilePaths[0]
						console.log(fileUrl);
						fileUp({
							file: fileUrl,
							info: {
								type_id: 2,
								user_id: that.userId
							}
						}).then(res => {
							var info = JSON.parse(res)
							console.log(num);
							if (info.code == 200) {
								if (num == 1) that.img_1 = info.data[0]
								if (num == 2) that.img_2 = info.data[0]
								if (num == 3) that.img_3 = info.data[0]
								if (num == 4) that.img_4 = info.data[0]
								if (num == 5) that.img_5 = info.data[0]
								if (num == 6) that.img_6 = info.data[0]
								if (num == 7) that.img_7 = info.data[0]
								if (num == 8) that.img_8 = info.data[0]
								console.log(that.img_1);
								// that.save()
							} else {
								uni.showToast({
									title: info.msg,
									icon: 'error',
									duration: 3000
								})
							}
						})
					}
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.content {
		/* background: white; */
		position: relative;
		overflow: hidden;
	}

	.info {
		margin: 40rpx 30rpx;
		padding: 40rpx 30rpx 40rpx;
		background-color: white;
		background: #FFFFFF;
		border-radius: 12rpx;
		overflow: hidden;

		.title {
			font-weight: 500;
			font-size: 32rpx;
		}

		.text {
			margin-top: 30rpx;

			text {
				color: #FF534E;
			}
		}

		.img_bg {
			width: 296rpx;
			height: 232rpx;
			background: #F9F9F9;
			border-radius: 12rpx;
			margin: 30rpx 0 0;
			display: inline-flex;
			align-items: center;
			justify-content: center;
			vertical-align: top;
			position: relative;

			&:nth-of-type(even) {
				margin-right: 38rpx;
			}

			image {
				margin-bottom: 30rpx;
			}

			.img_demo {
				width: 296rpx !important;
				height: 232rpx !important;
				margin: 0 !important;
				position: absolute;
				top: 0;
				left: 0;
			}

			.hint {
				width: 296rpx;
				height: 58rpx;
				line-height: 58rpx;
				text-align: center;
				background: #FFF3EE;
				border-radius: 0rpx 0rpx 12rpx 12rpx;
				position: absolute;
				left: 0;
				bottom: 0;
				color: #BC7A25;

				text {
					color: #FF0000;
					position: relative;
					top: 6rpx;
				}
			}
		}
	}

	.btn {
		margin: 80rpx auto 100rpx;
	}

	.color_9 {
		background: #999999;
	}

	/deep/ .uni-noticebar {
		width: 690rpx;
		background-color: #FFF3EE;
		border-radius: 59rpx;
		padding-left: 80rpx;
	}

	.notice {
		margin: 40rpx 30rpx;
		position: relative;

		image {
			position: absolute;
			left: 20rpx;
			top: 12rpx;
			width: 48rpx;
		}
	}
</style>